package com.e2edour.biz.aspect

import org.aspectj.lang.ProceedingJoinPoint
import org.aspectj.lang.annotation.Around
import org.aspectj.lang.annotation.Pointcut
import org.aspectj.lang.reflect.MethodSignature
import org.slf4j.LoggerFactory
import com.e2edour.biz.validator.ValidatorUtil
import com.e2edour.facade.abc.AbsResponse
import com.e2edour.facade.enums.ResCodeEnum
import com.e2edour.runtime.properties.AppContextConfig

/**
  * <p>
  *
  * @author King 
  * @since 2017/1/17
  */
class BizAspect {
  private val logger = LoggerFactory.getLogger(getClass)

  @Pointcut("execution(* com.cdj.cip.biz.impl.*.*(..))")
  def doAspect() {}

  @Around("doAspect()")
  @throws[ClassNotFoundException]
  @throws[IllegalAccessException]
  @throws[InstantiationException]
  def around(point: ProceedingJoinPoint): Any = {
    val signature = point.getSignature
    val methodSignature = signature.asInstanceOf[MethodSignature]
    val targetMethod = methodSignature.getMethod
    val args = point.getArgs

    for (arg <- args) {
      ValidatorUtil.validate(arg)
    }
    val _object = point.proceed
    //输出返回日志
    logger.info("{}{}.{}{}{}", Constants.LOG_FACADE_BACK, targetMethod.getDeclaringClass.getName, targetMethod.getName, Constants.LOG_SYMBOL, _object.toString)
    return _object
  }
}
